<%--
 *  File:    OrgCopyEr.jsp
 *  @Author: jianlin wang 
 *  Date:    2005-3-7 12:17
 *
 *  Copyright (C) 2000 - 2005 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
 

<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page import="com.oval.util.*" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>


<%
  	Category cat = Category.getInstance("jsp.OrgCopyEdit");  
%>

<%
	String strModuleName = "IMG";
	String privilegeCode = "Z0821";
    HashMap userInfo = (HashMap)session.getAttribute("userinfo");
    int intOrgid =((Integer)userInfo.get("orgid")).intValue();  	
  	
%>


<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<html>
<head>
<title>OrgCopyEr</title>
<PageFlow:CheckPageFlow pageName="porgcopyer"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="../js/ScriptLib.js"></script>
<script language="JavaScript"  src="../js/Calendar.js"></script>
<script language="JavaScript"  src="../js/FuncLib.js"></script>
<%
  String strIsNew=(String)pageContext.getAttribute("isnew");
  boolean isNew="Y".equals(strIsNew);
  String strDateTimeFormat=session.getAttribute("dateformat").toString()+" "+session.getAttribute("timeformat").toString();
%>
<script>
function isAllEnglish(s)	//Is the string s all English? All English:return true.
{
	var i,c;
	for(i=0;i<s.length;i++)
	{
		c=s.charAt(i);
		if((c>="A"&&c<="Z")||(c>="a"&&c<="z")||c=="_"||(c>=0&&c<=9))
		{
			if(c==" ")
				return false;
			continue;
		}
		else
			return false;
	}
	return true;
}
function page_save()
{
  if(!checkForm(thisform)) return;
  if(!isAllEnglish(thisform.adminname.value))
  {
    	alert("<%= message.getMessageDesc("ILLEGAL_FORMAT",label.getLabelName("L_AdmUserName",false)) %>");
    	return false;
  }  
  	
  if((thisform.adminname.value.length > 12)||(thisform.adminname.value.length < 4))
  {
    	alert("<%= message.getMessageDesc("LENGTH_MUST_BETWEEN",label.getLabelName("L_AdmUserName",false),"4", "12") %>");
    	return false;
  }
  if(thisform.adminpwd.value != thisform.adminpwdconfirm.value)
  {
    alert("<%= message.getMessageDesc("DIFFERENT_PASSWORD") %>");
    return ;
  } 
  if(thisform.adminpwd.value == thisform.adminname.value)
  {
    alert("<%= message.getMessageDesc("VALUE_MUST_NOTEQUAL",label.getLabelName("L_AdmPassword",false),label.getLabelName("L_AdmUserName",false)) %>");
    return ;
  } 
  var isnew = <%=JspHelper.filterNull( isNew )%>;
  if(isnew || (!isnew && !isEmpty(thisform.adminpwd.value)))
  {
    if((thisform.adminpwd.value.length > 16) || (thisform.adminpwd.value.length < 4))
    {
    	alert("<%= message.getMessageDesc("LENGTH_MUST_BETWEEN",label.getLabelName("L_AdmPassword",false),"4", "16") %>");
    	return;
    }	
    if(isCharsInBag(thisform.adminpwd.value,"0123456789"))
  	{
	  	alert("<%= message.getMessageDesc("VALUE_MUST_NOT_BE_ALL_NUMBER",label.getLabelName("L_AdmPassword",false)) %>");
		 	return;
	  }     
  }
  thisform.actionname.value="save";
  thisform.target = "_parent";
  isRunning = true;
  thisform.submit();  
  
}
function page_orgselect()
{
 
  var strUrl='ERSelectPop.jsp?<%= OvalTools.randomURL() %>&orgid=<custom:write name="orgcopyinfo" property="sourceorgid"/>&xorgid=<custom:write name="orgcopyinfo" property="sourceorgid"/>&xparentorgid=<custom:write name="orgcopyinfo" property="parentorgid"/>';
  var strStatus='height=400, width=800,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no';
  popwindow=window.open(strUrl,'newwindow',strStatus);
}
function page_setUser(id,name)
{   
    thisform.sourceusername.value= name;
    thisform.sourceuserid.value= id;
  
}


function page_orgchange(stype)
{
  var objid=eval("thisform."+stype+"orgid");
  var objcode=eval("thisform."+stype+"orgcode");
  var objname=eval("thisform."+stype+"orgname");
  objid.value="";
  objname.value="";
  if(!isEmpty(objcode.value))
  {
    thisform.reloadtype.value=stype;
    thisform.actionname.value="reload";
    thisform.target = "_self";
  	isRunning = true;
  	thisform.submit(); 
  }
}

function add_user()
{  thisform.actionname.value="adduserinit";
   thisform.target = "_self";
   isRunning = true;
   thisform.submit(); 
}
function page_add()
{  if(!checkForm(thisform)) return;
	 if(isEmpty(thisform.partnercode.value))
	 {
	    alert("<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_CopyEnterpriseCode",false))%>");
      return;
	 }
  if(!isNumeric(thisform.creditlimit.value))
  {
     alert("<%=message.getMessageDesc("VALUE_MUST_BE_NUMBER",label.getLabelName("L_CreditLimit",false))%>");
     return;
  }
  if(!isDate(thisform.creditexpiredate.value,'<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>'))
  {  
     alert("<%=message.getMessageDesc("VALUE_MUST_BE_DATE",label.getLabelName("L_CreditTime",false))%>");
     return;
  }
   thisform.actionname.value="add";
   thisform.target = "_self";
   isRunning = true;
   thisform.submit(); 
}
function  page_done()
{  if(!checkForm(thisform)) return;
   for(var i =0;i<thisform.numrows.value;i++)
   {   var credit_expire_date=eval("thisform.creditexpiredate" + i);
      var credit_limit=eval("thisform.creditlimit" + i);

      if(!isDate(credit_expire_date.value,'<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>'))
      {  
             alert("<%=message.getMessageDesc("VALUE_MUST_BE_DATE",label.getLabelName("L_CreditTime",false))%>");
             return;
      }

       if(!isNumeric(credit_limit.value))
     {
       alert("<%=message.getMessageDesc("VALUE_MUST_BE_NUMBER",label.getLabelName("L_CreditLimit",false))%>");
        return;
     }
       
   }

   thisform.actionname.value="done";
   thisform.target = "_self";
   isRunning = true;
   thisform.submit(); 
}
function page_delete()
{  

   
   if (isNullChecked(thisform.workids))
   {
    alert("<%= message.getMessageDesc("PLEASE_SELECT") %>");
    return;
   }

  if(!confirm('<%=message.getMessageDesc("ARE_YOU_SURE_DEL")%>'))
  {
       return;
  }
  thisform.actionname.value = "delete";
  thisform.target = "_self";
  isRunning = true;
  thisform.submit();

}
function page_setOrg(id,code,name,relationid)
{     
      thisform.partnerid.value=id;
      thisform.partnershortname.value=name; 
      thisform.partnercode.value=code;
      thisform.srcrelationdetailid.value=relationid;
}

</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"  Scroll=no >
<form name="thisform" method="post" action="../Dispatcher"  target="_parent">
          <input type="hidden" name="pagename" value="porgcopyer">
          <input type="hidden" name="actionname">
          <custom:hidden property="orgcopyid"/>
          <custom:hidden name="orgcopyinfo" property="sourceorgid" changedName="orgid"/>
          <input type="hidden" name="languagecode" value="<%= strLanguageCode %>">

<table id="topTable" border=0 cellpadding=0 cellspacing=0 width="100%">
  <tr> 
    <td valign=top>
        <table border=0 cellpadding=1 cellspacing=0 width="100%">
         
          <tbody> 
          <tr> 
            <td bgcolor=#000000 style="PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 0px"> 
              <table bgcolor=#000000 border=0 cellpadding=0 cellspacing=0 width="100%">
                <tr> 
                  <td  bgcolor=#ffffff style="PADDING-BOTTOM: 3px; PADDING-LEFT: 3px; PADDING-RIGHT: 3px; PADDING-TOP: 3px"> 
                   <div id=div2 style="HEIGHT: 400px; OVERFLOW: auto"> 
                      <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="1">
                         <% 
                             Vector CopyErInfo = (Vector)pageContext.getAttribute("copyerinfo");
                             if(CopyErInfo  == null)
                             {
                                 CopyErInfo  = new Vector();
                             }
                             String strClassType="td-listrom";
                             int j=0;
                           
                             int intSize = CopyErInfo.size();
                          %>
                          
                          <tr> 
                            <td colspan="12" class="td_right">
                              <a onclick="page_add();"><custom:button type="2" label="L_Add" imgsrc="add.gif" border="0" /></a>
                              <% 
                                  if(intSize!=0){
                              %>
                              <a onclick="page_done()"><custom:button type="2" label="L_Save" imgsrc="save.gif" border="0" /></a>
                              <a onclick="page_delete()"><custom:button type="2" label="L_Delete" imgsrc="delete.gif" border="0" /></a>
                              <%
                                  }
                              %>
                            </td>
                          </tr>
                          <tr class="deepblue-left">    
                            <td class="title_center" width="5%">&nbsp;</td>
                            <td class="title_center" width="10%"><%= label.getLabelName("L_CopyEnterpriseCode") %><span class="red">*</span></td>
                            <td class="title_center" ><%= label.getLabelName("L_EnterpriseName") %></td>
                            <td class="title_center" width="10%"><%= label.getLabelName("L_EnterpriseGroup") %></td>
                            <td class="title_center" width="10%"><%= label.getLabelName("L_BusinessArea") %></td>
                            <td class="title_center" width="10%"><%= label.getLabelName("L_BusinessContact") %></td>
                            <td class="title_center" width="10%"><%= label.getLabelName("L_ABC") %></td>
                            <td class="title_center" width="10%"><%= label.getLabelName("L_CreditLimit") %></td>
                            <td class="title_center" width="10%"><%= label.getLabelName("L_CreditTime") %></td>
                            <td class="title_center" width="10%"><%= label.getLabelName("L_Warehouse") %></td>
                          </tr>
    
                          <logic:iterate id="Items" collection="<%=CopyErInfo %>" indexId="idx">  
                            
                              <%
                                 String strOrgGroupId="orggroupid"+j;
                                 String strAreaId="areaid"+j;
                                 String strOrgCopyContactId="orgcopycontactid"+j;
                                 String strOrgCopyWarehouseId="orgcopywarehouseid"+j;
                                 Integer inde = new Integer(j);
                                 HashMap mapItems = (HashMap)pageContext.getAttribute("Items"); 
                              %>
                              <tr onmouseover="this.className='tr-over'" onmouseout="this.className='<%=JspHelper.filterNull(strClassType)%>'"  class="<%=JspHelper.filterNull(strClassType)%>">          
                                <td ><input type="checkbox" name="workids"  value="<custom:write name="Items" property="orgcopyerid"  />" class="normalradio" ><input type="hidden" name="orgcopyerid<%=JspHelper.filterNull(j )%>" value="<custom:write name="Items" property="orgcopyerid"  />"></td>
                                <td><custom:write name="Items" property="partnercode" nbsp="true"  /></td>
                                <td><custom:write name="Items" property="partnershortname" nbsp="true" /></td>
                                <td><custom:select optionsName="groupinfo"    optionValueKey="orggroupid"         optionInnerTextKey="groupname"   name="Items"  property="orggroupid" colIndex="<%=inde %>" defaultValue="-------" /></td>
                                <td><custom:select optionsName="areatreeinfo" optionValueKey="areaid"             optionInnerTextKey="areaname"    name="Items"  property="areaid"     colIndex="<%=inde %>" defaultValue="-------" /></td>
                                <td><custom:select optionsName="contactinfo"  optionValueKey="orgcopycontactid"   optionInnerTextKey="contactname" name="Items"  property="contactid"  colIndex="<%=inde %>" defaultValue="-------" /></td>
                                <td><input type="text" name="abccode<%=JspHelper.filterNull(j)%>"  value="<custom:write name="Items" property="abccode"  />" size="10" ></td>
                                <td><input type="text" name="creditlimit<%=JspHelper.filterNull(j)%>"  value="<custom:write name="Items" property="creditlimit"  />"size="10" ></td>
                                <td>
                                     <input type="text" name="creditexpiredate<%=JspHelper.filterNull(j)%>"   value="<custom:write name="Items" property="creditexpiredate"  />" dataFormat="<%=JspHelper.filterNull(strDateTimeFormat)%>" size="10" />
                                     <a onclick="javascript:c.show(this,'thisform.creditexpiredate<%=JspHelper.filterNull(j)%>','<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>')"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
                                </td>
                                <td><custom:select optionsName="warehouseinfo" optionValueKey="orgcopywarehouseid"  optionInnerTextKey="warehousename"  name="Items"  property="warehouseid" colIndex="<%=inde %>" defaultValue="-------"  /></td>
                                
                             </tr>
                               
                             <% j++; %>
                          </logic:iterate>
                              <input type="hidden" name="numrows" value=<%=JspHelper.filterNull(CopyErInfo.size())%>>                          
                          <tr>
                             <td>&nbsp;</td>
                             <td width="10%">
                                <custom:text name="addcopyer" property="partnercode"  readonly="true" size="5" />
                                <custom:hidden name="addcopyer" property="partnerid" />
                                <custom:hidden name="addcopyer" property="srcrelationdetailid" />
                                <a onclick="page_orgselect();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                             </td>
                             <td><custom:text name="addcopyer" property="partnershortname" readonly="true" size="25" /></td>
                             <td><custom:select optionsName="groupinfo" optionValueKey="orggroupid"   optionInnerTextKey="groupname"   property="orggroupid" defaultValue="-------"/></td>
                             <td><custom:select optionsName="areatreeinfo" optionValueKey="areaid"   optionInnerTextKey="areaname"   property="areaid" defaultValue="-------" /></td>
                             <td><custom:select optionsName="contactinfo" optionValueKey="orgcopycontactid"   optionInnerTextKey="contactname"   property="contactid" defaultValue="-------" /></td>
                             <td><custom:text name="addcopyer" property="abccode" size="10" /></td>
                             <td><custom:text name="addcopyer" property="creditlimit" size="10" /></td>
                             <td width="12%">
                                <input type="text" name="creditexpiredate"  dataFormat="<%=JspHelper.filterNull(strDateTimeFormat)%>" size="10" />
                                <a onclick="javascript:c.show(this,'thisform.creditexpiredate','<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>')"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
                             </td>
                             
                             <td><custom:select optionsName="warehouseinfo" optionValueKey="orgcopywarehouseid"   optionInnerTextKey="warehousename"   property="warehouseid" defaultValue="-------"/></td>              
                          </tr> 
                      </table>
                    </div>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
          </tbody> 
         
        </table>
    </td>
  </tr>
  <tr> 
    <td class=summary_top></td> 
  </tr>
  <%@include file="OrgCopyBtn.inc"%>
</table>
</form>
</body>
</html>
